#coding=utf-8
import requests,json,urllib
import platform_login_api
import mysql_password
#签到脚本
def sign(phone):
    password = mysql_password.password(phone)
    s = requests.session()
    headers = platform_login_api.login(phone)[0]  #获取到登录后的headers
    sign = s.put('http://community-platform-api-test.gdgyun.com/api/community/reward/sign',headers=headers)  #进行签到
    msg = sign.json()["msg"]
    signedDetail = s.get('http://community-platform-api-test.gdgyun.com/api/community/reward/signedDetail',headers=headers)  #获取签到天数的页面
    signedDetail_days = signedDetail.json()["data"]["signedDays"]  #获取连续签到天数
    coinsDetail = s.get('http://community-platform-api-test.gdgyun.com/api/community/reward/silver/coinsDetail?isIncoming=',headers=headers)  #获取银币明细
    sign_record = coinsDetail.json()["data"][0]["desc"]  #获取desc字段值
    coins = coinsDetail.json()["data"][0]["coins"]  #获取银币数量
    #判断签到是否成功
    if str(msg) == '当天签到成功':
        print u'当天签到成功，累计签到天数为：'+str(signedDetail_days)+u'天，获得金币：'+str(coins)
        return u'当天签到成功，累计签到天数为：'+str(signedDetail_days)+u'天'+str(coins)
    else:
        print u'签到失败'
        return u'签到失败'

if __name__ == '__main__':
    sign('17781108472')